var clientHeight = window.innerHeight;
console.log(clientHeight);
$("#body-left").height(clientHeight);
$("#body-right").height(clientHeight);

function showAnswer(){
    document.getElementById("answer").style.display="inline";
}

function hiddenAnswer(){
    document.getElementById("answer").style.display="none";
}

var nowPageId = 0;

function beforePage() {
    if(nowPageId >1) {
        nowPageId--;
        getSuanFa();
        updateSuanfaTitle();
        hiddenAnswer();
    }
}

function afterPage() {
    nowPageId++;
    getSuanFa();
    updateSuanfaTitle();
    hiddenAnswer();
}

function jumpPage() {
    var page = document.getElementById("nowPageId").value;
    if(page!=null && page!= undefined && page != "" && page > 0){
        nowPageId = page;
        getSuanFa();
    }
    updateSuanfaTitle();
    hiddenAnswer();
}

function getSuanFa() {
    $.ajax({
        type: "GET",
        async: false,
        url: "/suanfa?id="+nowPageId,
        contentType: "application/x-www-form-urlencoded",
        success: function(result) {
            console.log(result);
            updateQandS(result);
        },
        error: function(result) {

        }
    });
}

function updateQandS(result){
    if(result.flag == 1){
        var question = result.question;
        var answer = result.answer;
        document.getElementById("question").innerHTML = question;
        document.getElementById("answer").innerHTML = answer;

    }else{
        alert("题目"+nowPageId+"不存在！");
    }
}

function updateSuanfaTitle() {
    document.getElementById("suanfaTitle").innerHTML = "算法题"+ nowPageId;

}

//页面加载后先跳转到第一页
afterPage();